<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
<h1>ahao-swoole-ws测试</h1>
<script>
  // var wsUrl = "ws://47.98.176.141:8812";
  var wsUrl = "ws://47.98.176.141:8812/websocket";

  var websocket = new WebSocket(wsUrl);
  alert(1);
  //实例对象的onopen熟悉
  websocket.onopen = function (evt) {
      alert(2);
      websocket.send("hello-sinwa")
      console.log("connected-swoole-success");
  }

  //实例化onmessage
  websocket.onmessage = function (evt) {
      console.log("ws-server-return-data:" + evt.data)
  }

  //实例化onclose事件
  websocket.onclose = function (evt) {
      console.log("close")
  }

  //onerror
  websocket.onerror = function (evt, e) {
      console.log("error" + evt.data)
  }

</script>
</body>
</html>